using System.IO;
using System.Xml;
using System.Xml.Serialization;

namespace Curriculum.Business.LectorDatos
{
	/// <summary>
	/// Summary description for LectorPresentaciones.
	/// </summary>
	public class LectorPresentaciones
	{
		private string _path = null;

		public string Path
		{
			get { return this._path; }
			set { this._path = value;}
		}

		public LectorPresentaciones()
		{}

		public Presentaciones Leer(string nroVersion)
		{
			XmlSerializer s = new XmlSerializer(typeof(Presentaciones));

			TextReader fs;

			if (this._path == null)
			{
				// Deserialization
				string dir=System.Configuration.ConfigurationSettings.AppSettings["pathDirectorioDeTrabajo"];
				//string dir = @"..\..\..\ArchivosXml";

				this._path = dir +"V"+nroVersion+@"\HV"+nroVersion+".xml";
			}

			try
			{
				fs = new StreamReader(this._path);
			}
			catch
			{
				return null;
			}
			
			XmlReader reader = new XmlTextReader(fs);
          
			// Declare an object variable of the type to be deserialized.
			Presentaciones presentaciones;

			// Use the Deserialize method to restore the object's state.
			presentaciones = (Presentaciones) s.Deserialize(reader);

			fs.Close();

			return presentaciones;
		}

		public void Escribir(Presentaciones presentaciones, string nroVersion)
		{
			XmlSerializer serializador = new XmlSerializer(typeof(Presentaciones));

			string dir=System.Configuration.ConfigurationSettings.AppSettings["pathDirectorioDeTrabajo"];
			//string dir = @"..\..\..\ArchivosXml";

			FileStream writer;
			writer = new FileStream(dir +"V"+nroVersion+@"\HV"+nroVersion+".xml",System.IO.FileMode.Create);

			serializador.Serialize(writer,presentaciones);

			writer.Close();

		}
	}
}
